Gray level correction for correcting brightness and contrast in an image which is captured under an illumination condition such as a condition where a subject is photographed against the light is known, and gamma correction and histogram correction are typical examples of the gray level correction. With gamma correction and histogram correction, however, as image correction is performed using a fixed coefficient, problems of an image being white due to overexposure and an image being black due to underexposure arise.
On the other hand, adaptive gray level correction (adaptive enhancement) in which, in addition to the gray level value of image data, information concerning pixels adjacent to a pixel to be corrected is used to determine correction coefficients has been proposed, and with this technology, correction in accordance with the content of an image can be achieved. The adaptive gray level correction is disclosed in “Comparison of Retinex Models for Hardware Implementation” by Nosato et al., IEICE technical report, SIS, 2005-16, pp. 19-24 (June, 2005). The adaptive gray level correction is based on Retinex theory, in which assuming that an input image is represented by a product of illumination light and reflectivity, illumination light is separated from an input image to thereby obtain a reflectivity image as a correction image. Provided that an input image I is represented as an input image I=illumination light L×reflectivity R (correction image), the relationship of R (x, y)=exp {log(I(x,y))−log(L(x,y))} can be achieved. Calculus of variation is used to estimate the illumination light, and a plurality of layers k with a resolution which is ½k that of the original image are generated, and calculation for updating the illumination light is repeated starting from a layer with a lower resolution. Here, the calculation for updating the illumination light is performed by using the expression of L (x, y)=L (x, y)−μNSD×G(x, y), wherein G(x, y) is a gradient of cost function and μNSD is learning coefficient. Specifically, processing in which G(x, y) is first calculated, and μNSD(x, y) is then calculated, and based on these calculation results, L(x, y) is calculated, is repeated.
Further, JP2008-27967A discloses that when a person photographing mode is selected, an image is captured with the exposure value being set to a value under an appropriate exposure value computed by an AE (Automatic Exposure) detector, and gray level correction is applied to image data obtained by image capturing by using a γ transform table for increasing the dynamic range of image data which has been subjected to gray level conversion processing, thereby correcting the brightness value of portions of the image with insufficient brightness which are located in the vicinity of the center of the subject.
As described above, problems of an image being white due overexposure and an image being black due to underexposure can be prevented by capturing an image of a subject with the exposure value being set under the appropriate exposure value which is set by AE and adaptively performing gray level correction with respect to the resulting image data. With this method, however, certain image data may suffer from hue shift caused by the gray level correction, resulting in a disadvantage that an image desired by a user cannot be obtained. For example, when adaptive gray level correction is performed with respect to image data obtained by capturing an image with the exposure value being set lower than the appropriate exposure value by 0.5 EV, an image of blue sky which existed in the original image data prior to the gray level correction becomes unclear. Further, if the original image data prior to the gray level correction includes an image of flowers with an orange color, the color of the flowers becomes yellowish as a result of the gray level correction.